/**
 */
package com.dingpeikeji.quickdeer.core.modules.tschedef.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.dingpeikeji.quickdeer.core.common.config.Global;
import com.dingpeikeji.quickdeer.core.common.persistence.Page;
import com.dingpeikeji.quickdeer.core.common.utils.StringUtils;
import com.dingpeikeji.quickdeer.core.common.web.BaseController;
import com.dingpeikeji.quickdeer.core.modules.tschedef.entity.TSchedefDrvs;
import com.dingpeikeji.quickdeer.core.modules.tschedef.service.TSchedefDrvsService;

/**
 * 班次定义司机Controller
 * @author Zhaoy
 * @version 2016-06-03
 */
@Controller
@RequestMapping(value = "${adminPath}/tschedef/tSchedefDrvs")
public class TSchedefDrvsController extends BaseController {

	@Autowired
	private TSchedefDrvsService tSchedefDrvsService;
	
	@ModelAttribute
	public TSchedefDrvs get(@RequestParam(required=false) String id) {
		TSchedefDrvs entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = tSchedefDrvsService.get(id);
		}
		if (entity == null){
			entity = new TSchedefDrvs();
		}
		return entity;
	}
	
	@RequiresPermissions("tschedef:tSchedefDrvs:view")
	@RequestMapping(value = {"list", ""})
	public String list(TSchedefDrvs tSchedefDrvs, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<TSchedefDrvs> page = tSchedefDrvsService.findPage(new Page<TSchedefDrvs>(request, response), tSchedefDrvs); 
		model.addAttribute("page", page);
		return "modules/tschedef/tSchedefDrvsList";
	}

	@RequiresPermissions("tschedef:tSchedefDrvs:view")
	@RequestMapping(value = "form")
	public String form(TSchedefDrvs tSchedefDrvs, Model model) {
		model.addAttribute("tSchedefDrvs", tSchedefDrvs);
		return "modules/tschedef/tSchedefDrvsForm";
	}

	@RequiresPermissions("tschedef:tSchedefDrvs:edit")
	@RequestMapping(value = "save")
	public String save(TSchedefDrvs tSchedefDrvs, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, tSchedefDrvs)){
			return form(tSchedefDrvs, model);
		}
		tSchedefDrvsService.save(tSchedefDrvs);
		addMessage(redirectAttributes, "保存班次定义司机成功");
		return "redirect:"+Global.getAdminPath()+"/tschedef/tSchedefDrvs/?repage";
	}
	
	@RequiresPermissions("tschedef:tSchedefDrvs:edit")
	@RequestMapping(value = "delete")
	public String delete(TSchedefDrvs tSchedefDrvs, RedirectAttributes redirectAttributes) {
		tSchedefDrvsService.delete(tSchedefDrvs);
		addMessage(redirectAttributes, "删除班次定义司机成功");
		return "redirect:"+Global.getAdminPath()+"/tschedef/tSchedefDrvs/?repage";
	}

}
